package baiqitun.stupro.security.util;

import baiqitun.stupro.common.util.excel.ExcelDataSaver;
import baiqitun.stupro.common.util.excel.ExcelParser;
import baiqitun.stupro.common.util.excel.MapExcelParser;
import baiqitun.stupro.security.entity.SysUser;
import baiqitun.stupro.security.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * 用户信息保存器
 * @author kedaji
 */
public abstract class AbstractUserInfoSaver implements ExcelDataSaver {

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void save(InputStream is, Map<String, String> args) {
        MapExcelParser parser = new MapExcelParser();
        String createBy = args.get("createBy");
        String departId = args.get("departId");
        List<Map<String, Object>> rows = parser.parse(is);
        for (Map<String, Object> row: rows){
            save(row, createBy, departId);
        }
    }

    /**
     * 自定义用户信息保存逻辑
     * @param row Excel一行的信息
     * @param createBy 创建人用户名
     * @param departId 部门id
     */
    protected abstract void save(Map<String, Object> row, String createBy, String departId);
}
